﻿@model MvcPaging.PaginationModel
<ul class="pagination">
    @foreach (var link in Model.PaginationLinks)
    {
        @BuildLink(link)
    }
</ul>
@helper BuildLink(MvcPaging.PaginationLink link)
    {
    var liBuilder = new TagBuilder("li");
    if (link.IsCurrent)
    {
        liBuilder.MergeAttribute("class", "active");
    }
    if (!link.Active)
    {
        liBuilder.MergeAttribute("class", "disabled");
    }

    var aBuilder = new TagBuilder("a");
    if (link.Url == null)
    {
        aBuilder.MergeAttribute("href", "javascript:void(0)");
    }
    else
    {
        aBuilder.MergeAttribute("href", link.Url);
    }

    // Ajax support
    if (Model.AjaxOptions != null)
    {
        foreach (var ajaxOption in Model.AjaxOptions.ToUnobtrusiveHtmlAttributes())
        {
            aBuilder.MergeAttribute(ajaxOption.Key, ajaxOption.Value.ToString(), true);
        }
    }
    
    // 
    


    if (link.DisplayText == "«")
    {
        aBuilder.SetInnerText("←");
    }
    else if (link.DisplayText == "»")
    {
        aBuilder.SetInnerText("→");
    }
    else
    {
        aBuilder.SetInnerText(link.DisplayText);
    }
    liBuilder.InnerHtml = aBuilder.ToString();

    @Html.Raw(liBuilder.ToString())
}